package com.cloudpan.controller;

import com.cloudpan.common.R;
import com.cloudpan.entity.bo.SysFindFriendBo;
import com.cloudpan.entity.bo.SysFriendRequestBo;
import com.cloudpan.entity.vo.SysAppealFriendListVo;
import com.cloudpan.entity.vo.SysFriendVo;
import com.cloudpan.service.SysFriendRequestService;
import com.cloudpan.service.SysUserFriendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author sc
 * @DATE 2023/11/8 11:29
 * @Description:
 * @Version 1.0
 */
@RestController
@RequestMapping("/sys/friend")
@Slf4j
@RequiredArgsConstructor
@Api(value = "好友控制器", tags = "好友控制器")
public class SysFriendController {

    private final SysUserFriendService friendService;

    private final SysFriendRequestService sysFriendRequestService;

    @GetMapping("/getfriend/{userid}")
    @ApiOperation(value = "获取当前用户的所有好友")
    public R<List<SysFriendVo>> getUserFriendList(@PathVariable("userid") String userid){
        return R.ok(friendService.getFriendList(userid));
    }

    @GetMapping("/findfriend")
    @ApiOperation(value = "搜索其他用户的信息")
    public R<List<SysFriendVo>> findfriend(@RequestBody SysFindFriendBo friendBo){
        List<SysFriendVo> list =  friendService.findList(friendBo);
        return R.ok(list);
    }

    @DeleteMapping("/del/{id}")
    @ApiOperation(value = "删除好友")
    public R<String> del(@PathVariable("id") String id){
        return friendService.removeById(id)?R.ok("删除成功"):R.failed("删除失败");
    }

    @PostMapping("/appeal")
    @ApiOperation(value = "申请添加好友")
    public R<String> addFriend(@RequestBody SysFriendRequestBo requestBo){
        Boolean result = sysFriendRequestService.addFriend(requestBo);
        return result?R.ok("申请成功"):R.failed("申请失败");
    }

    @GetMapping("/reOrAg")
    @ApiOperation(value = "同意或拒绝好友申请接口")
    public R<Boolean> reOrAg(@RequestBody SysFriendRequestBo requestBo){
        Boolean result = sysFriendRequestService.reOrAg(requestBo);
        return R.ok(result);
    }

    @ApiOperation(value = "查询当前用户已经申请的好友申请列表")
    @GetMapping("/getAppeal/{userid}")
    public R<List<SysAppealFriendListVo>> getAppeal(@PathVariable("userid") String userid){
        List<SysAppealFriendListVo> list = sysFriendRequestService.getAppeal(userid);
        return R.ok(list);
    }



}
